import { Component, OnInit } from '@angular/core';
import { uniqueId } from 'lodash';
import { OptionItem } from '@iux/live';

interface DemoUser {
  id: string;
  name: string;
  age: number;
  expand: boolean;
  random: number;
  disabled: boolean;
  children?: DemoUser[];
}

@Component({
  selector: 'app-demo5',
  templateUrl: './demo5.component.html',
  styles: []
})
export class Demo5Component implements OnInit {

  data: OptionItem[];
  value: {[key: string]: any};
  index = 0;
  selectedValue;
  constructor() { }

  ngOnInit() {
    this.initData();
  }

  initData() {
    this.data = Array.from({length: 10}).map((item, key) => {
      return this.initUser(key, key % 2 !== 0);
    });
  }

  initUser(key: number, disabled: boolean) {
    return {
      id: uniqueId('uid'),
      label: `user${key}`,
      age: 10 + key,
      expand: false,
      random: parseInt(Math.random() * 100 + ''),
      disabled: disabled,
      isLeaf: true
    };
  }

  filterChange(value: string) {
    console.log('search value', value);
  }

  change(value) {
    console.log('change', value)
  }
}
